package com.jk.service;

import com.jk.dao.TreeDao;
import com.jk.entity.TreeEntity;
import com.jk.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class TreeService {
    @Autowired
    private TreeDao treeDao;
    public List<TreeEntity> getTree(Integer pid) {
        List<TreeEntity> list=treeDao.getTree(pid);
        for (int i = 0; i < list.size(); i++) {
            List<TreeEntity> list2=getTree(list.get(i).getId());
            list.get(i).setNodes(list2);
        }
        return  list;
    }

    public String login(String num, String pwd , HttpServletRequest request) {
        UserEntity user= treeDao.login(num,pwd);
        if (user!=null) {
            request.getSession().setAttribute("user", user);
            return "200";
        }
            return "500";
    }
}
